package com.extension.company.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.extension.company.admin.R;
import com.extension.company.common.utils.DisplayUtils;

/**
 * 问题反馈的适配器
 */
public class FeedBackAdapter extends BaseAdapter {

	private Context context;
	private LinearLayout.LayoutParams params;
	private int ColumnWidth;

	public FeedBackAdapter(Context context) {
		this.context = context;
		int screenWidth = DisplayUtils.getScreenWidth(context);
		int dp_15 = DisplayUtils.convertDip2Px(context, 15);
		int dp_12 = DisplayUtils.convertDip2Px(context, 12);
		ColumnWidth = (screenWidth - dp_15 * 4 - dp_12 * 3) / 4;
		params = new LinearLayout.LayoutParams(ColumnWidth, ColumnWidth);
	}

	@Override
	public int getCount() {
		return 4;
	}

	@Override
	public Object getItem(int i) {
		return null;
	}

	@Override
	public long getItemId(int i) {
		return 0;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		ViewHolder viewHolder = null;
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.feedback_item, null);
			viewHolder = new ViewHolder();
			viewHolder.iv_photo = view.findViewById(R.id.iv_photo);
			viewHolder.iv_photo.setLayoutParams(params);
			view.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) view.getTag();
		}
		if (i == 3) {
			viewHolder.iv_photo.setImageResource(R.drawable.tianjiatup);
		} else {
			viewHolder.iv_photo.setImageResource(R.drawable.img_defaut);
		}
		return view;
	}

	class ViewHolder {
		public ImageView iv_photo;
	}

	public int getColumnWidth() {
		return ColumnWidth;
	}
}
